package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

//执行update语句
public class JDBCDemo03 {
    public static void main(String[] args) throws Exception{
        //需求 修改userinfo 表中ID为1的信息
        //连接服务器
        Class.forName("com.mysql.cj.jdbc.Driver");
        //加载驱动
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        //创建
        Statement statement = connection.createStatement();
        //创建sql语句
        String sql = "UPDATE userinfo SET password = '666',nickname='小三', age=12 WHERE id=1";
        int i = statement.executeUpdate(sql);
        if (i>0){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
        connection.close();
    }
}
